package mastetAndWorker;

import java.util.Map;
import java.util.Objects;
import java.util.Queue;

public abstract class Worker implements Runnable {

    public Queue<Object> getWorkQueue() {
        return workQueue;
    }

    public void setWorkQueue(Queue<Object> workQueue) {
        this.workQueue = workQueue;
    }

    public Map<String, Object> getResultMap() {
        return resultMap;
    }

    public void setResultMap(Map<String, Object> resultMap) {
        this.resultMap = resultMap;
    }

    protected Queue<Object> workQueue;

    protected Map<String, Object> resultMap;


    @Override
    public void run() {
        while (true) {
            Object input = workQueue.poll();

            if (Objects.isNull(input))
                break;
            Object res = handle(input);

            resultMap.put(Integer.toString(input.hashCode()), res);
        }
    }


     abstract Object handle(Object input);

}
